var nowing='1';//1可以执行  2 执行中
var page=1;//定位当前页数
var index = 1;
var forEnd =0;
var showPage=10;//初始化最多显示的页数
var showPageCount=10;//初始化每页显示的条数

initMenu();//初始化二级菜单

//初始化二级菜单
function initMenu(){
	$.ajax({
		  type: "post",
		  url: "../menu/querySecondMenuQian",
		  data: {
			  'parentId':parent
			  },
		  dataType: "json",
		  success: function(data){
			  var parentMenu = data.parentMenu;//父级菜单
			  var menuList = data.menuList;//二级菜单集合
			  $("#modulename").html(parentMenu.text);
			  $("#titleId").html(parentMenu.text);
			  $("#textbluebId").html(parentMenu.text);
			  
			  var menuStr ='';
			   $.each(menuList, function(index, entity){ 
				   var houUrl=entity.qianUrl;
				   var shuzu =[];
				   shuzu = houUrl.split('menu=');
				   var cktype = '';
				   if(shuzu.length>=2){
					   cktype=shuzu[1];
					   var shuzu2 = [];
					   shuzu2 = cktype.split('&');
					   if(shuzu2.length>=1){
						   cktype=shuzu2[0];
					   }
				   }
				   
				   menuStr+='<a href="javascript:loadData('
					   +cktype
					   +',1,'
					   +showPageCount
					   +',1);"><li id="id'+cktype+'" class='
					   +(entity.id==menu?"presentnav":"")
					   +'>'
					   +entity.text
					   +'</li></a>'; 
				   if(entity.id==menu){
					   loadData(cktype,page,showPageCount,1);
				   }
			    })
			    $("#pagenavId").append(menuStr); 
		  }
	  }) 
	  
}

//点击二级菜单时触发
function loadData(ckType,page,showPageCount,isInit){
	if(nowing=='2'){
		alert("正在查询...");
		return;
	}
	nowing='2';
	if(isInit==1){
		page=1;//定位当前页数
		index = 1;	
		forEnd =0;
	}
	$("#list").empty();
	$("#pagnub").empty();
	$("#pagenavId li").removeClass("presentnav");
	$("#id"+ckType).attr("class","presentnav");
	$.ajax({
			  type: "post",
			  url: "../xyService/queryXyHtml",
			  data: {
				  'ckType':ckType,
				  'state':'1' ,//1是显示  2是删除
				  'sort':'yes',
				  'page':page,
				  'rows':showPageCount
				  },
			  dataType: "json",
			  error:function(){
				  nowing='1';
			  },
			  success: function(data){
				  var rows = data.rows;//集合
				  var total=data.total;//总条数
				  
				  var rowsStr='';
				  $.each(rows, function(index, entity){
					  var nowDate = entity.inputDate;
					  var now = new Date(nowDate);
					  var time= now.format("yyyy-MM-dd");
					  rowsStr+='<a target="_blank" href="credit_service_query.html?sys_id='
						  +entity.sysId
						  +'"><li><span>'
						  +time
						  +'</span>'
						  +entity.mc
						  +'</li></a>';
				  })   
				  $("#list").append(rowsStr);
				  var pageAll = Math.ceil(total/showPageCount);//总页数
	
				  if(page==1){
					  forEnd = pageAll;
					  if(forEnd>=showPage){
						  forEnd=showPage;
					  }
				  }
				  
				  var totalStr1='<a href="javascript:loadBegin('+ckType+');">'
				  	  +'<span class="top"></span></a>'
				      +'<a href="javascript:loadUp('+ckType+','+page+');">'
				      +'<span class="arrowleft"></span></a>';
				  var totalStr2='';
				 
				  
				  for (var i = index; i <=forEnd; i++) {
					
					if(page==i){
						totalStr2+='<a  id="aid'+i+'"' 
						+'href="javascript:loadIndex('+ckType+','+i+');"><b>'+i+'</b></a>';
					}else{
						totalStr2+='<a id="aid'+i+'"' 
						+'href="javascript:loadIndex('+ckType+','+i+');"><span>'+i+'</span></a>';
					}
				  }
				  if(forEnd<pageAll){
					  totalStr2+=' ......';
				  }
				 var totalStr = totalStr1+totalStr2;
				  totalStr+='<a href="javascript:loadNext('+ckType+','+page+','+pageAll+');">'
				      +'<span class="arrowrightactive"></span></a>'
				      +'<a href="javascript:loadEnd('+ckType+','+pageAll+');">'
				      +'<span class="bottomactive"></span></a>';
				  $("#pagnub").append(totalStr);

					nowing='1';
				 
			  }
		 })
		 
}


var dataId = getQueryString2('sysId');
initDetailData();//初始化明细页面的数据
function getQueryString2(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
 }
//初始化明细页面的数据
function initDetailData(){
	$.ajax({
		  type: "post",
		  url: "../xyService/queryXyService",
		  data: {
			  'sysId':dataId
			  },
		  dataType: "json",
		  success: function(data){
			  var ls = data.list;
			  $(ls).each(function(){ 
				  $("#xm").html(this.mc);
				  $("#sfzhm").html(this.sfzhm);
				  $("#lxdh").html(this.mc);
				  $("#email").html(this.email);
				  $("#tszt").html(this.mc);
				  $("#yyms").html(this.mc);
				  
			  }); 
//			  $("#titleId").html(entity.typeName);//类型名称
//			  $("#textbluebId").html(entity.typeName);
//			  $("#newstitleId").html(entity.title);//内容名字
//			  var nowDate = entity.createTime;
//			  var now = new Date(nowDate);
//			  var time= now.format("yyyy年MM月dd日");
//			  $("#timeId").html(time);//创建时间
//			  $("#summaryId").html(entity.summary);//来源
//			  $("#newstext").html(entity.html);//具体内容  
		  }
	  }) 
	  
}




Date.prototype.format = function(format){
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(), //day
	"h+" : this.getHours(), //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter
	"S" : this.getMilliseconds() //millisecond
	}

	if(/(y+)/.test(format)) {
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
	if(new RegExp("("+ k +")").test(format)) {
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	}
	}
	return format;
	} 